package com.panda.system.controller;

import com.panda.common.annotation.Log;
import com.panda.common.core.controller.BaseController;
import com.panda.common.core.domain.AjaxResult;
import com.panda.common.core.page.TableDataInfo;
import com.panda.common.enums.BusinessType;
import com.panda.common.utils.poi.ExcelUtil;
import com.panda.system.domain.PandaTaskDetail;
import com.panda.system.service.IPandaTaskDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 任务完成明细Controller
 * 
 * @author ruoyi
 * @date 2021-01-02
 */
@RestController
@RequestMapping("/system/detail")
public class PandaTaskDetailController extends BaseController
{
    @Autowired
    private IPandaTaskDetailService pandaTaskDetailService;

    /**
     * 查询任务完成明细列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PandaTaskDetail pandaTaskDetail)
    {
        startPage();
        List<PandaTaskDetail> list = pandaTaskDetailService.selectPandaTaskDetailList(pandaTaskDetail);
        return getDataTable(list);
    }

    /**
     * 导出任务完成明细列表
     */
    @Log(title = "任务完成明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PandaTaskDetail pandaTaskDetail)
    {
        List<PandaTaskDetail> list = pandaTaskDetailService.selectPandaTaskDetailList(pandaTaskDetail);
        ExcelUtil<PandaTaskDetail> util = new ExcelUtil<PandaTaskDetail>(PandaTaskDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 获取任务完成明细详细信息
     */
    @GetMapping(value = "/{taskDetailId}")
    public AjaxResult getInfo(@PathVariable("taskDetailId") Long taskDetailId)
    {
        return AjaxResult.success(pandaTaskDetailService.selectPandaTaskDetailById(taskDetailId));
    }

    /**
     * 新增任务完成明细
     */
    @Log(title = "任务完成明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PandaTaskDetail pandaTaskDetail)
    {
        return toAjax(pandaTaskDetailService.insertPandaTaskDetail(pandaTaskDetail));
    }

    /**
     * 修改任务完成明细
     */
    @Log(title = "任务完成明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PandaTaskDetail pandaTaskDetail)
    {
        return toAjax(pandaTaskDetailService.updatePandaTaskDetail(pandaTaskDetail));
    }

    /**
     * 删除任务完成明细
     */
    @Log(title = "任务完成明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskDetailIds}")
    public AjaxResult remove(@PathVariable Long[] taskDetailIds)
    {
        return toAjax(pandaTaskDetailService.deletePandaTaskDetailByIds(taskDetailIds));
    }
}
